/*
Author: Dave Lenz
Creation date: 15 jun 2009
 */

package nl.ypmits.utils.as3.view.bug {

	public class Bug extends ABug {
	/*
		private var _graphic : Sprite;
		private var t1 : Number;
		private var t2 : Number;
		private var rc : Number; // rollcounter
		private var cc : Number; // colcounter
		private var cx : Number; // cx
		private var cy : Number; // cy
		private var ds : Number; // ds
		private var t : Number; // temp
		private var dw : Number;
		private var s : Number;

		public function Bug( _stepy : Number, _cw : Number, stage : Stage = null, bounds : Rectangle = null )
		{
			stage ? stage = stage : throw new Error("ERROR! You should set the stage in the Bug-constructor!");
			bounds ? boundsrect = bounds : boundsrect = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
			
			fillSinCos( 1, 4 );

			stepy = _stepy;
			cw = _cw;
			
			graphic.graphics.clear( );
			graphic.graphics.beginFill( Math.random( ) * 0, .5 );
			graphic.graphics.drawCircle( 0, 0, 20 );
			graphic.graphics.endFill( );
			graphic.graphics.lineStyle( 1, 0xFF9900, .5 );
			graphic.graphics.lineTo( -10, 0 );
			graphic.graphics.moveTo( 10, 0 );
			graphic.graphics.lineTo( 0, -10 );
			graphic.graphics.moveTo( 0, 10 );
			
			// init sincos
			t1 = 0;
			t2 = 0;
			rc = 0;
			cc = 0;
			
			//effects
			cx = 0;
			cy = 1;
			ds = 1; 
			t = 1;

			//init random
			dw = 5;
			s = 3;
			
			addListeners( );
		}

		
		public function start() : void
		{
			addEventListener( Event.ENTER_FRAME, enter );
		}

		
		public function stop() : void
		{
			removeEventListener( Event.ENTER_FRAME, enter );
		}

		
		private function enter(event : Event) : void
		{
			var mx : Number;
			var my : Number;
			var dd : Number; // delta_dir
			var dl : Number; // delta
			var mt : Number; // my_theta
			var mr : Number; // my_theta_rad
			var nx : Number; // new x
			var ny : Number; // new y
			mt = rotation;
			dd = Math.random( ) * 2;
			if (dd == 0) 
			{
				dd = -1;
			}
			dl = dw * dd;
			mt = mt + dl + stepy;
			mr = (mt * Math.PI) / 180;
			
			nx = x + ((3 + cw) * Math.cos( mr ));
			ny = y + ((3 + cw) * Math.sin( mr ));
			
			if ((nx >= _bounds.x) && (nx <= _bounds.width)) 
			{
				x = nx;
			} 
			else 
			{
				mt = 180 - mt;
			}
			if ((ny > _bounds.y) && (ny < _bounds.height)) 
			{
				y = ny;
			} 
			else 
			{
				mt = -mt;
			}
			rotation = mt + (-ds + 21) * 18;
		}

		
		private function addListeners() : void
		{
			addEventListener( MouseEvent.MOUSE_DOWN, mouseHandler );
			_stage.addEventListener( MouseEvent.MOUSE_UP, mouseHandler );
		}

		
		private function mouseHandler(event : MouseEvent) : void
		{
			if( event.type == MouseEvent.MOUSE_DOWN ) 
			{
				startDrag( false );
			}
			else if ( event.type == MouseEvent.MOUSE_UP) 
			{
				stopDrag( );
			}
		}

		
		private function fillSinCos( stepx : Number, stepy : Number ) : void 
		{
			var a : int = 0;
			var b : int = 0;
			var x : int = 0;
			while (x <= 360) {
				aC[x] = Math.round( Number( (Math.cos( (a * Math.PI) / 180 )) ) + Number( (Math.cos( (b * Math.PI) / 180 )) ) );
				aS[x] = Math.round( Number( (Math.sin( (a * Math.PI) / 180 )) ) + Number( (Math.sin( (b * Math.PI) / 180 )) ) );
				trace( aC[x], aS[x] );
				a += stepx;
				b += stepy;
				if (a >= 360) a = 0;
				if (b >= 360) b = 0;
				x++;
			}
					// fix voor lijntjes trekken (weggehaald... niet meer nodig)
		}
		
		
		
		
		
		
		
		
		
		
		public function get graphic() : Sprite
		{
			return _graphic;
		}
		
		
		public function set graphic(graphic : Sprite) : void
		{
			_graphic = graphic;
		}
	*/
	}
}
